import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}






public class leetcodecome1118 {


    public static int maxProduct(String[] words) {

        for (int i = 0; i < words.length; i++) {
            String word = words[i];


            char[] chars = word.toCharArray();

            List<Character> characters = new ArrayList<>();
            for (char aChar : chars) {
                characters.add(aChar);
            }
            characters.sort(new Comparator<Character>() {
                @Override
                public int compare(Character o1, Character o2) {
                    return o1-o2;
                }
            });

            StringBuffer stringBuffer = new StringBuffer();
            for (Character character : characters) {
                stringBuffer.append(character);
            }

            words[i] = stringBuffer.toString();

        }




        int max=0;
        for (int i = 0; i < words.length; i++) {
            for (int j = i+1; j <words.length ; j++) {
                String wordA = words[i];
                String wordB = words[j];

                char[] charsA = wordA.toCharArray();
                char[] charsB = wordB.toCharArray();

                boolean isHave=false;
                for (char c : charsA) {
                    for (char c1 : charsB) {
                        if (c-c1==0){
                            isHave=true;
                            break;
                        }
                    }
                }
                if (!isHave){
                    max=wordA.length()*wordB.length()>max?wordA.length()*wordB.length():max;
                }

            }
        }

        return max;


    }





    public static void main(String[] args) {
        String [] test={"abcw","baz","foo","bar","xtfn","abcdef"};
        System.out.println(maxProduct(test));

    }

    //smqian
    public int findTilt(TreeNode root) {

        if (root==null) return 0;
        return findTilt(root.left)+findTilt(root.right)+Math.abs(sum(root.left)-sum(root.right));
    }

    private int sum(TreeNode right) {

        if (right==null)
            return 0;
        return right.val+sum(right.left)+sum(right.right);
    }


}
